clear all
set more off
capture log close
log using "$output/figure1.log", replace

version 16	

use "$data/ctctaxsim_kid123mar12.dta", clear
gen totctc=v22+v23

gen ctc2021=totctc+depx*1000
replace ctc2021=3000*depx if earnings<50000 
replace ctc2021=max(ctc2021-0.05*(earnings-75000),2000*depx) if earnings>=75000 & mstat==1
replace ctc2021=max(0,2000*depx-0.05*(earnings-200000)) if earnings>=200000 & mstat==1

replace ctc2021=max(ctc2021-0.05*(earnings-150000),2000*depx) if earnings>=150000 & mstat==2
replace ctc2021=max(0,2000*depx-0.05*(earnings-400000)) if earnings>=400000 & mstat==2

replace earnings=earnings/1000
keep if earnings<550
sort earnings
replace totctc=totctc/1000
replace ctc2021=ctc2021/1000

twoway line totctc earnings if year==2017 & depx==1 & mstat==1, pstyle(p1) || line totctc earnings if year==2017 & depx==1 & mstat==2, lp(-) pstyle(p1) || line totctc earnings if year==2017 & depx==2 & mstat==1, pstyle(p2)  || line totctc earnings if year==2017 & depx==2 & mstat==2, lp(-) pstyle(p2) || line totctc earnings if year==2017 & depx==3 & mstat==1, pstyle(p3)  || line totctc earnings if year==2017 & depx==3 & mstat==2, lp(-) pstyle(p3) graphregion(color(white)) bgcolor(white) ylabel(0(3)9) leg(order(1 "Single" 2 "Married") c(1) pos(1) ring(0)) ytitle("CTC Benefits ($1000s)") xtitle("Earnings ($1000s)") text(4 50 "3 Kids" , j(left) size(medsmall)) text(.00 50 "1 Kid" , j(left) size(medsmall)) text(2.00 50 "2 Kids" , j(left) size(medsmall)) xlabel(0(100)500) text(10 250 "{bf:Panel A: 2017 CTC}" , box fc(white) margin(small) j(left) size(medsmall))
graph save "$output/ctc2017.gph", replace

twoway line totctc earnings if year==2018 & depx==1 & mstat==1, pstyle(p1) || line totctc earnings if year==2018 & depx==1 & mstat==2, lp(-) pstyle(p1) || line totctc earnings if year==2018 & depx==2 & mstat==1, pstyle(p2)  || line totctc earnings if year==2018 & depx==2 & mstat==2, lp(-) pstyle(p2) || line totctc earnings if year==2018 & depx==3 & mstat==1, pstyle(p3)  || line totctc earnings if year==2018 & depx==3 & mstat==2, lp(-) pstyle(p3) graphregion(color(white)) bgcolor(white) ylabel(0(3)9) leg(off) ytitle("CTC Benefits ($1000s)") xtitle("Earnings ($1000s)") text(7.00 120 "3 Kids" , j(left) size(medsmall)) text(1.00 120 "1 Kid" , j(left) size(medsmall)) text(3.00 120 "2 Kids" , j(left) size(medsmall)) xlabel(0(100)500) text(10 250 "{bf:Panel B: 2020 CTC}" , box fc(white) margin(small) j(left) size(medsmall))
graph save "$output/ctc2018.gph", replace


twoway line ctc2021 earnings if year==2018 & depx==1 & mstat==1, pstyle(p1) || line ctc2021 earnings if year==2018 & depx==1 & mstat==2, lp(-) pstyle(p1) || line ctc2021 earnings if year==2018 & depx==2 & mstat==1, pstyle(p2)  || line ctc2021 earnings if year==2018 & depx==2 & mstat==2, lp(-) pstyle(p2) || line ctc2021 earnings if year==2018 & depx==3 & mstat==1, pstyle(p3)  || line ctc2021 earnings if year==2018 & depx==3 & mstat==2, lp(-) pstyle(p3) graphregion(color(white)) bgcolor(white) ylabel(0(3)9) leg(off) ytitle("CTC Benefits ($1000s)") xtitle("Earnings ($1000s)") text(8.00 40 "3 Kids" , j(left) size(medsmall)) text(2.00 40 "1 Kid" , j(left) size(medsmall)) text(5.00 40 "2 Kids" , j(left) size(medsmall)) xlabel(0(100)500) text(10 250 "{bf:Panel C: 2021 CTC}" , box fc(white) margin(small)  j(left) size(medsmall))
graph save "$output/ctc2021.gph", replace

graph combine "$output/ctc2017.gph" "$output/ctc2018.gph" "$output/ctc2021.gph" ,graphregion(color(white)) c(1)
graph export "$output/figure1.png", replace

erase "$output/ctc2017.gph" 
erase "$output/ctc2018.gph" 
erase "$output/ctc2021.gph"

log close